import React, { useRef } from 'react';
import {
  Form,
  Input,
  Tooltip,
  Icon,
  Cascader,
  Select,
  Row,
  Col,
  Checkbox,
  Button,
  Radio,
  DatePicker,
  AutoComplete,
  TreeSelect,
} from 'antd';
import { connect } from 'dva';

const { Option } = Select;
const { TreeNode } = TreeSelect;
const AutoCompleteOption = AutoComplete.Option;

export interface isProps {
  auth?: any;
  form?: any;
  mode?: string; // view 、 edit 、add
  close?: () => void;
  submit?: (view: any, data: any) => void;
}

export default class Index extends React.Component<isProps, any> {
  handleSubmit = () => {
    const { close, submit, auth } = this.props;
    this.props.form.validateFieldsAndScroll((err: any, values: any) => {
      if (!err) {
        console.log(submit, close, 333);
        close && close();
        submit && submit(auth, values);
      }
    });
  };

  render() {
    const { getFieldDecorator } = this.props.form;
    console.log(this.props, 4444);
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
    };
    const treeData = [
      {
        title: 'Node1',
        value: '0-0',
        key: '0-0',
        children: [
          {
            title: 'Child Node1',
            value: '0-0-1',
            key: '0-0-1',
          },
          {
            title: 'Child Node2',
            value: '0-0-2',
            key: '0-0-2',
          },
        ],
      },
      {
        title: 'Node2',
        value: '0-1',
        key: '0-1',
      },
    ];
    return (
      <Form {...formItemLayout} onSubmit={this.handleSubmit}>
        <Form.Item label="标签">
          {getFieldDecorator('label', {
            rules: [
              {
                required: true,
              },
            ],
          })(<Input />)}
        </Form.Item>
        <Form.Item label="键值">
          {getFieldDecorator('value', {
            rules: [
              {
                required: true,
              },
            ],
          })(<Input />)}
        </Form.Item>
        <Form.Item label="行业标准码">
          {getFieldDecorator('standardCode', {
            rules: [{}],
          })(<Input />)}
        </Form.Item>
        <Form.Item label="类型">
          {getFieldDecorator('type', {
            rules: [
              {
                required: true,
              },
            ],
          })(<Input />)}
        </Form.Item>
        <Form.Item label="排序">
          {getFieldDecorator('sort', {
            rules: [
              {
                required: true,
              },
            ],
          })(<Input />)}
        </Form.Item>
        <Form.Item label="描述">
          {getFieldDecorator('description', {
            rules: [
              {
                required: true,
              },
            ],
          })(<Input />)}
        </Form.Item>
      </Form>
    );
  }
}
